package com.rjkj.medicalwaste.utils;

import android.annotation.SuppressLint;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * Created by Administrator on 2018/12/20.
 */

public class TimeUtils {
    /*垃圾袋二维码*/
    public static String getTimeStr() {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        //Log.e("time",strTime);
        return simpleDateFormat.format(date);
    }

    /*年月日 格式：yyyy-MM-dd HH:mm:ss*/
    public static String getYMDTime() {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }
    /*年月日 格式：yyyy-MM-dd HH:mm:ss*/
    public static String getYMDHMSTime() {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }
    /*年月日 格式：yyyy-MM-dd HH:mm:ss*/
    public static String getHMSTime() {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

    /*年月日 格式：yyyy-MM-dd HH:mm:ss*/
    public static String getHMTime(Date date) {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");// HH:mm:ss
        return simpleDateFormat.format(date);
    }
    public static String getTimestampToString(Timestamp timestamp) {
        String time = timestamp.toString();
        if (time.contains(".")) {
            time = time.split("\\.")[0];
        }
        return time;
    }
    @SuppressLint("SimpleDateFormat")
    public static Date transToTimeStamp(String date){
        try {
            return new SimpleDateFormat("yy-MM-dd hh:mm:ss").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String getTimeStr(Date date) {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");// HH:mm:ss

        //Log.e("time",strTime);
        return simpleDateFormat.format(date);
    }
    public static String getYYMMDDHHMMSS(String s) {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");// HH:mm:ss
        //Log.e("time",strTime);
        return simpleDateFormat.format(Objects.requireNonNull(transToTimeStamp(s)));
    }
    public static String getTimestampToSubmitString(Timestamp timestamp) {
        String time = "";
        if (timestamp != null) {
            time = timestamp.toString();
            int index = time.indexOf(".");
            if (index > -1) {
                time = time.substring(0, index);
            }
        }
        return time;
    }

}
